<?php

namespace app\controllers;

use yii\web\Controller;
use yii\helpers\Url;
use yii\web\Response;

use app\models\Cs;
use app\models\Bug;
use app\models\User;

class IndexController extends Controller
{

    public function actionIndex()
    {
       /* $cs = new Cs;
        $cs->getUser();
        echo "</br>";
        echo "来自index的控制器 欢迎使用";
        echo "</br>";
        print_r(Url::to(['Index/index'],true)) ;*/
        $arr = array('title'=>'来自index的控制器 欢迎使用','content'=>'hi man  your ok?');
        //print_r($arr);
        return $this->renderPartial('index',$arr);
    }


    /**
     * 变量传递到视图  视图控制器后面只能大写   驼峰法改为小写中间加- {post-view} 
     * @Author huchao
     * @Date   2019-08-09
     * @return [type]     [description]
     */
    public function actionPostView($name)
    {

    	//id 展示页面参数访问
        //print_r($arr);
        //直接渲染页面 传递变量
        $id = Url::to(['index/PostView','id'=>$name,'name'=>"i don t no"],true);
        $arr = array(
        	'title'=>'来自postviews的控制器 欢迎使用',
        	'content'=>'hi man  your ok?',
        	'id'=>$id,
        );
        return $this->renderPartial('postviews',$arr);
    }

    /**
     * 数据库操作
     * @Author huchao
     * @Date   2019-08-12
     * @return [type]     [description]
     */
    public function actionGetList()
    {
    	$qurey= new Bug;

    	$qurey->getlist();
    }

    /**
     * 获取用户
     * @Author huchao
     * @Date   2019-08-12
     * @return [type]     [description]
     */
    public function actionGetUser()
    {
    	$qurey = new User;
    	$id = 2;
    	$qurey->getUser($id);
    }

    /**
     * 添加用户
     * @Author huchao
     * @Date   2019-08-12
     * @return [type]     [description]
     */
    public function actionAddUser()
    {
    	$qurey = new User;
    	$status = $qurey->addUser('媚哥的小芒果',123456);
    	//$response = \Yii::$app->response;
		//$response->format = \yii\web\Response::FORMAT_JSON;
    	return ['success'=>$status];
    }


}
